﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace StickTops
{

    public partial class StickTop : Form
    {
        private Point LastCursorPosition;
        private bool IsMouseDown = false;
        private MainForm MainFormRef;
        private string LabelText;


        /// <summary>
        /// Make new StickTop
        /// </summary>
        /// <param name="Label">The Label</param>
        /// <param name="MainFormRefrence">The Owner of the sticktop you create</param>
        public StickTop(String Label, MainForm MainFormRefrence)
        {
            InitializeComponent();
            LabelText = Label;
            MainFormRef = MainFormRefrence;
        }

        private void StickTop_Load(object sender, EventArgs e)
            {
                ResizePic.BackColor = Properties.Settings.Default.MainBack;
                MainTextBox.BackColor = Properties.Settings.Default.MainBack;
                MainTextBox.ForeColor = Properties.Settings.Default.MainFore;
                MainLabel.BackColor = Properties.Settings.Default.LabelBack;
                MainLabel.ForeColor = Properties.Settings.Default.LabelFore;
            }


        
        #region "Move"

        private void MainLabel_MouseDown(object sender, MouseEventArgs e)
        {
            this.IsMouseDown = true;
            this.LastCursorPosition = new Point(e.X, e.Y);
        }

        private void MainLabel_MouseMove(object sender, MouseEventArgs e)
        {
            if (this.IsMouseDown == true)
            {
                 //Move the form
                 this.Location = new Point(this.Left - (this.LastCursorPosition.X - e.X), this.Top - (this.LastCursorPosition.Y - e.Y));
                 
                 //Redraw the form//
                 this.Invalidate();
            }

}

        private void MainLabel_MouseUp(object sender, MouseEventArgs e) 
        {
             this.IsMouseDown = false;
        }

        #endregion

        #region "Resize"

            private void ResizePic_MouseDown(object sender, MouseEventArgs e)
            {
                IsMouseDown = true;
                this.LastCursorPosition = new Point(e.X, e.Y);
            }

            private void ResizePic_MouseMove(object sender, MouseEventArgs e)
            {
                if (this.IsMouseDown == true)
                {

                        //Resize the form
                        this.Size = new Size(this.Size.Width + (e.X - LastCursorPosition.X), this.Size.Height + (e.Y - LastCursorPosition.Y));
                        //Redraw the form//
                        this.Invalidate();
                   
                }
            }

            private void ResizePic_MouseUp(object sender, MouseEventArgs e)
            {
                this.IsMouseDown = false;
            }
        #endregion

        #region "LabelMenu"

        private void newToolStripMenuItem_Click(object sender, EventArgs e)
                    {
                        MainFormRef.MakeNewNote("NoName");
                    }

            private void CloseStripMenuItem_Click(object sender, EventArgs e)
                    {
                        this.Close();
                    }

        #endregion

        #region "Color"

            private void topTextToolStripMenuItem_Click(object sender, EventArgs e)
            {
                ColorDialog ColorDia = new ColorDialog();
                ColorDia.AllowFullOpen = true;
                ColorDia.Color = Properties.Settings.Default.LabelFore;
                ColorDia.ShowDialog();

                MainLabel.ForeColor = ColorDia.Color;
                Properties.Settings.Default.LabelFore = ColorDia.Color;
            }

            private void topBackgroundToolStripMenuItem_Click(object sender, EventArgs e)
            {
                ColorDialog ColorDia = new ColorDialog();
                ColorDia.AllowFullOpen = true;
                ColorDia.Color = Properties.Settings.Default.LabelBack;
                ColorDia.ShowDialog();

                MainLabel.BackColor = ColorDia.Color;
                Properties.Settings.Default.LabelBack = ColorDia.Color;
            }

            private void bottomTextToolStripMenuItem_Click(object sender, EventArgs e)
            {
                ColorDialog ColorDia = new ColorDialog();
                ColorDia.AllowFullOpen = true;
                ColorDia.Color = Properties.Settings.Default.MainFore;
                ColorDia.ShowDialog();

                MainTextBox.ForeColor = ColorDia.Color;
                Properties.Settings.Default.MainFore = ColorDia.Color;
            }

            private void bottomBackgroundToolStripMenuItem_Click(object sender, EventArgs e)
            {
                ColorDialog ColorDia = new ColorDialog();
                ColorDia.AllowFullOpen = true;
                ColorDia.Color = Properties.Settings.Default.LabelBack;
                ColorDia.ShowDialog();

                MainTextBox.BackColor = ColorDia.Color;
                Properties.Settings.Default.LabelBack = ColorDia.Color;
                ResizePic.BackColor = ColorDia.Color;
            }

#endregion


            private void toolStripTextBox1_Click(object sender, EventArgs e)
            {
                if (toolStripTextBox1.Text == "NoName")
                {
                    toolStripTextBox1.Text = "";
                    toolStripTextBox1.Focus();
                }
            }

            private void toolStripTextBox1_TextChanged(object sender, EventArgs e)
            {
                MainLabel.Text = toolStripTextBox1.Text;
            }

            private void toolStripTextBox1_Leave(object sender, EventArgs e)
            {
                if (toolStripTextBox1.Text == "") 
                {
                    MainLabel.Text = "NoName";

                }


            }


            private void toolStripTextBox2_TextChanged(object sender, EventArgs e)
            {
                int NewFontSize;
                if (int.TryParse(toolStripTextBox2.Text,out NewFontSize))
                {
                    Font NewSize = new Font(MainTextBox.SelectionFont.FontFamily, int.Parse(toolStripTextBox2.Text));
                    MainTextBox.SelectionFont = NewSize;
                }
            }

            



    }

        
}

